package com.tamecode.bean.anno;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class AutowiredTest {

    @Autowired(required = false)
    @Qualifier("testService")
    private TestService testService;

    private TestService testService2;

    private TestService testService3;

    private TestService testService4;

    private LogService logService;

    @Autowired // 将 TestService 传给方法入参
    public void setTestService2(TestService testService2) {
        this.testService2 = testService2;
    }

    // 将名为 testService 的 bean 传给方法入参
    @Autowired
    @Qualifier("testService")
    public void setTestService3(TestService testService2) {
        this.testService2 = testService2;
    }

    // 多个方法入参的注入
    // LogService 的入参是注入名为 logService 的 bean；而 TestService 的入参是注入 TestService 类型的 bean。
    @Autowired
    public void init(@Qualifier("logService") LogService logService, TestService testService4){
        System.out.println("muti param inject");
        this.logService = logService;
        this.testService4 = testService4;
    }

}
